﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="/Scripts/jquery-3.3.1.js"></script>
    <script>
        $(function () {
            var Ticket = localStorage.getItem("userData_Ticket");
            var UserName = localStorage.getItem("userData_UserName");
            if (Ticket != null && Ticket != "") {
                var html = `<span id="user">${UserName}<a href="javascript:void(0);" onclick="Exit()">退出</a></span>`;
                $("#user").html(html);
            }

            $.ajax({
                type: "get",
                url: "http://localhost:27221/api/Home/test3",
                data: {},
                beforeSend: function (XHR) {
                    //发送ajax请求之前向http的head里面加入验证信息
                    XHR.setRequestHeader('Authorization', 'BasicAuth ' + Ticket);
                },
                success: function (data, status) {
                    if (status == "success") {
                        $("#div_test").html(data.name);
                    }
                },
                error: function (e) {
                    $("#div_test").html("无权限访问");
                },
                complete: function () {

                }

            });
        });

        function Exit() {
            localStorage.clear();
            window.location = "/";
        }
    </script>
</head>
<body>
    欢迎界面。<span id="user"><a href="/User/Login.html">登录</a></span>
    <div id="div_test"></div>
</body>
</html>